package com.ruoyi.web.controller.ring;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ring.domain.HealthQuestionAnswer;
import com.ruoyi.ring.service.IHealthQuestionAnswerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 问卷答案Controller
 * 
 * @author liuwp
 * @date 2025-07-29
 */
@RestController
@RequestMapping("/ring/health_question_answer")
public class HealthQuestionAnswerController extends BaseController
{
    @Resource
    private IHealthQuestionAnswerService healthQuestionAnswerService;

    /**
     * 查询问卷答案列表
     */
    @PreAuthorize("@ss.hasPermi('ring:health_question_answer:list')")
    @GetMapping("/list")
    public TableDataInfo list(HealthQuestionAnswer healthQuestionAnswer)
    {
        startPage();
        List<HealthQuestionAnswer> list = healthQuestionAnswerService.selectHealthQuestionAnswerList(healthQuestionAnswer);
        return getDataTable(list);
    }

    /**
     * 导出问卷答案列表
     */
    @PreAuthorize("@ss.hasPermi('ring:health_question_answer:export')")
    @Log(title = "问卷答案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HealthQuestionAnswer healthQuestionAnswer)
    {
        List<HealthQuestionAnswer> list = healthQuestionAnswerService.selectHealthQuestionAnswerList(healthQuestionAnswer);
        ExcelUtil<HealthQuestionAnswer> util = new ExcelUtil<HealthQuestionAnswer>(HealthQuestionAnswer.class);
        util.exportExcel(response, list, "问卷答案数据");
    }

    /**
     * 获取问卷答案详细信息
     */
    @PreAuthorize("@ss.hasPermi('ring:health_question_answer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(healthQuestionAnswerService.selectHealthQuestionAnswerById(id));
    }

    /**
     * 新增问卷答案
     */
    @PreAuthorize("@ss.hasPermi('ring:health_question_answer:add')")
    @Log(title = "问卷答案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthQuestionAnswer healthQuestionAnswer)
    {
        return toAjax(healthQuestionAnswerService.insertHealthQuestionAnswer(healthQuestionAnswer));
    }

    /**
     * 修改问卷答案
     */
    @PreAuthorize("@ss.hasPermi('ring:health_question_answer:edit')")
    @Log(title = "问卷答案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthQuestionAnswer healthQuestionAnswer)
    {
        return toAjax(healthQuestionAnswerService.updateHealthQuestionAnswer(healthQuestionAnswer));
    }

    /**
     * 删除问卷答案
     */
    @PreAuthorize("@ss.hasPermi('ring:health_question_answer:remove')")
    @Log(title = "问卷答案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(healthQuestionAnswerService.deleteHealthQuestionAnswerByIds(ids));
    }

}
